var $ = function(text) {
    return document.getElementById(text);
}
// 搜索
function handler() {
    var a = $("txt");
    var url = "https://www.baidu.com/s?wd=" + a.value;
    window.open(url);
}
$("but").onclick = function() {
    handler();
}
$("txt").onkeyup = function(event) {
    if (event.keyCode === 13) {
        handler();
    }
}
// 搜索框变色
$("txt").onfocus = function() {
    document.getElementsByClassName('search2')[0].style.border = "1px solid #38f";
}
$("txt").onblur = function() {
    document.getElementsByClassName('search2')[0].style.border = "1px solid #b8b8b8";
}

// 右下拉菜单
window.onload = function() {
    $("box").onmouseover = function() {
        $("box-div").style.display = "block";
        $("box").style.backgroundColor = "#f9f9f9";
        $("box").style.color = "#555";
    }
    $("box").onmouseout = function() {
        $("box-div").style.display = "none";
        $("box").style.backgroundColor = "#398bfb";
        $("box").style.color = "#fff";
    }

    // 天气下拉菜单
    $("weather-but").onmouseover = $("weather").onmouseover = function() {
        $("weather").style.display = 'block';
        clearTimeout($("weather-but")['timeout']);
    }
    $("weather-but").onmouseout = $("weather").onmouseout = function() {
        var timeout = setTimeout(function() {
            $("weather").style.display = 'none';
        },
        100);
        clearTimeout($("weather-but")['timeout']);
        $("weather-but")['timeout'] = timeout;
    }

    /*导航栏*/
    var but_top = document.getElementsByClassName("button-top")[0];
    var but_mid = document.getElementsByClassName("button-mid")[0];

    but_top.onclick = function() {
        if (but_mid.style.display === "none") {
            but_mid.style.display = "block";
            $("icon1").className = "icon-angle-down";
        } else {
            but_mid.style.display = "none";
            $("icon1").className = "icon-angle-right";
        }
    }

    $("mid11").onmouseover = function() {
        $("none_right").style.display = "block";
    }
    $("mid11").onmouseout = function() {
        $("none_right").style.display = "none";
    }

    /*个人设置*/

    $("user").onmouseover = function() {
        $("menu").style.display = "block";
    }
    $("user").onmouseout = function() {
        $("menu").style.display = "none";
    }
    $("user1").onmouseover = function() {
        $("menu1").style.display = "block";
    }
    $("user1").onmouseout = function() {
        $("menu1").style.display = "none";
    }

    // 滚轮事件
    $("body").onwheel = function() {
        $("home8").style.display = "none";
    }

    // 弹出添加
    $("add").onclick = function() {
        $("menu_up").style.display = "block";
        $("up1").style.display = "block";
    }
    $("menu_up").onclick = $("remove5").onclick = function() {
        remove8();
    }
    function remove8() {
        $("menu_up").style.display = "none";
        $("up1").style.display = "none";
    }

    //删除导航
    $("edit").onclick = function() {
        remove();
        over();
    }

    function remove() {
        var a1 = $("button_mid").children;
        for (var i = 0; i < a1.length; i++) {
            var a2 = document.getElementsByClassName("m2")[i].children;
            for (var j = 1; j < a2.length; j++) {
                var remove = document.createElement("i");
                remove.id = "removeId" + '_' + i + '_' + j;
                remove.setAttribute("onclick", "remove_div(" + remove.id + ")");
                remove.className = "icon-remove";
                a2[j].appendChild(remove);
            }
        }
    }
}
function over() {
    var a = $("none_right");
    var but = document.createElement("div");
    but.className = "over";
    but.setAttribute("id", "over");
    but.setAttribute("onclick", "over()");
    a.innerHTML = "";
    var b = document.getElementsByClassName("m1")[0];
    b.appendChild(but);
    but.innerHTML = "完成";

    $("over").onclick = function() {
        over1();
    }
}

// 删除单个节点
function remove_div(Id) {
    Id.parentNode.parentNode.removeChild(Id.parentNode);
}
